/**
 * 我的页面
 */

app.controller('myCtrl', function ($scope, $http, $rootScope, dialogsManager) {

	var url = 'http://qa.aixingfu.net/v1/api-member/get-member-detail?memberId=' + $rootScope.globalInfo.user.ids;
	$http({
		method: 'get',
		url: url,
	}).then(function (data) {
		console.log(data)
		$scope.ids = $rootScope.globalInfo.user.ids;
		$scope.username = data.data.username;
		$scope.pic = data.data.pic;
		$scope.sex = data.data.sex;
	}, function (error) {
		console.log(error);
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})

	//点击跳转课程页面首页
	$rootScope.backCourse = function () {
		$state.go('tab.course')
	}
	//跳转二维码页面
	$scope.myTowCode = function () {
		location.href = '#/tab/my/myTowCode';
	}

	//跳转个人信息页面
	$scope.myMessage = function () {
		location.href = '#/tab/my/myMessage';
	}
	//跳转设置页面
	$scope.mySet = function () {
		location.href = '#/tab/my/mySet';
	}
	//跳转选择会员卡详情
	$scope.membershipCardDetailsCodeClick = function () {
		location.href = '#/tab/my/membershipCardDetails';
	}
	//跳转购买的私课
	$scope.privateLessonsPurchasedClick = function () {
		location.href = '#/tab/my/privateLessonsPurchased';
	}
	//跳转购买的私课
	$scope.lockerClick = function () {
		location.href = '#/tab/my/locker';
	}
});

/**
 * 会员卡列表
 */
app.controller("membershipCardDetailsCodeCtrl", function ($scope, $http, dialogsManager, $ionicHistory, $rootScope) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$http({ method: 'get', url: 'http://qa.aixingfu.net/v1/api-member/get-member-card-all?memberId=' + $rootScope.globalInfo.user.ids }).then(function (data) {
		$scope.items = data.data.data;
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})
	$scope.onclick = function (id) {
		$rootScope.memberCardId = id;
		location.href = '#/tab/my/membershipCardDetailsB/' + id;
	}

})
/**
 * 会员卡详情
 */
app.controller("membershipbCodeCtrl", function ($scope, $http, dialogsManager, $ionicHistory, $rootScope) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$http({ method: 'get', url: 'http://qa.aixingfu.net/v1/api-member/get-member-info?memberId=' + $rootScope.globalInfo.user.ids + "&memberCardId=" + $rootScope.memberCardId }).then(function (data) {
		$scope.items = data.data.data
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})


})
/**
 * 购买的私课
 */
app.controller('privateLessonsPurchasedCtrl', function ($scope, $http, dialogsManager, $ionicHistory, $rootScope) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$scope.initData = function () {
		$http({ method: 'get', url: 'http://qa.aixingfu.net/v1/api-private/get?memberId=' + $rootScope.globalInfo.user.ids }).then(function (data) {
			$scope.items = data.data
		}, function (error) {
			console.log(error)
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}
	$scope.initData();

	$scope.onclick = function (id) {
		$rootScope.idsws1 = id;
		location.href = '#/tab/my/privateTeachChatsDetailA/' + id;
	}
})
//购买私教课详情 
app.controller('privateTeachChatsDetailA', function ($rootScope, $scope, $stateParams, $http, $ionicHistory, $state, dialogsManager) {
	//返回上一页
	$scope.backPrivate = function () {
		$ionicHistory.goBack();
	}

	var url = 'http://qa.aixingfu.net/v1/api-private/get-detail?id=' + $rootScope.idsws1 + '&memberId=' + $rootScope.globalInfo.user.ids;

	$http({
		url: url,
		method: 'GET',
	}).success(function (date) {
		$scope.items = date;
	}).error(
		function (data) {
			console.log(data);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		}
		);

	$rootScope.date = '4';
	// 跳转 产品课程
	$scope.productCourse = function () {
		location.href = '#/tab/my/productCourse/' + $rootScope.idsws;
	}
	// 选择时间
	$scope.ionFooterButton = function () {
		if ($scope.items.orderStatus == false) {
			$scope.showMessage = function () {
				dialogsManager.showMessage("您课程已经上完了！");
			}
			$scope.showMessage();
			$('#leagueDetailsButtons').attr('disabled', 'disabled')
			return
		}
		location.href = '#/tab/my/selectTime/' + $rootScope.idsws1
	}
	//地图 
	$scope.mapClick = function () {
		location.href = '#/tab/my/map/' + $rootScope.idsws1;
	}
})
//购买私教课购买产品详情
/**
 * 产品课程
 */
app.controller('productCourseBCtrl', function ($rootScope, $scope, $stateParams, $http, dialogsManager) {

	var url = 'http://qa.aixingfu.net/v1/api-private/get-class-package-detail?id=' + $rootScope.idsws1

	$http({
		url: url,
		method: 'GET',
	}).success(function (date) {
		$scope.items = date;

		for (var key in $scope.items.packageClass) {
			if ($scope.items.packageClass.hasOwnProperty(key)) {
				if ($scope.items.packageClass[key].status == 1) {
					$scope.aaa = 'ion-checkmark-circled';
				}
				if ($scope.items.packageClass[key].status == 2) {
					$scope.aaa = '';
				}
			}
		}
	}).error(
		function (data) {
			console.log(data);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		}
		);

})
/**
 * 选择时间 预约教练
 */
app.controller('selectTimeCCtrl', function ($rootScope, $scope, $stateParams, $location, $state, $ionicHistory, $http, $sce, $ionicPopup, dialogsManager) {

	$scope.selectDate = getDate();
	var url = 'http://qa.aixingfu.net/v1/api-coach/get-coach?venueId=' + $rootScope.globalInfo.user.venueId;

	$http({
		url: url,
		method: 'GET',
	}).success(function (date) {
		$scope.items = date;
	}).error(
		function (data) {
			console.log(data);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		}
		);


	$scope.selectOrderOne = function ($event, id) {
		$('.selectOrderOne').removeClass('selectOrder')
		$($event.target).addClass('selectOrder')
		// 获取教练id
		$scope.coachId = id;
	}


	$scope.data = { result: "" };
	// 定义时间回调函数
	$scope.callback = function (value) {
		// 获取预约时间
		$scope.dates = value;
		return false;
	}


	$scope.yuke = function () {
		if ($scope.dates == undefined) {
			var time = getNowFormatDate();
			$scope.dates = time;
		}
		var document = { classId: $rootScope.idsws1, memberId: $rootScope.globalInfo.user.ids, classType: 'charge', coachId: $scope.coachId, classDate: $scope.dates }
		if (document) {
			if (document.coachId == '' || document.coachId == undefined || document.coachId != $scope.coachId) {
				$scope.showMessage = function () {
					dialogsManager.showMessage("请选择教练");
				}
				$scope.showMessage();
			}
		}

		if (document.coachId != undefined) {
			var url = 'http://qa.aixingfu.net/v1/api-about-record/set-about-record';
			$http({
				method: 'post',
				url: url,
				headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
				data: $.param(document)
			}).then(function (success) {
				$ionicHistory.clearCache();
				$state.go('tab.privateLessonsE', {}, { reload: true })
			}, function (error) {
				console.log(error);
				$scope.showMessage = function () {
					dialogsManager.showMessage('系统错误,请联系工作人员');
				}
				$scope.showMessage();
			})

		}
	}
})
/**
 * 更衣柜
 */
app.controller("lockerCtrl", function ($scope, $http, dialogsManager, $ionicHistory, $rootScope) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$http({ method: 'get', url: 'http://qa.aixingfu.net/v1/api-member/get-member-cabinet?memberId=' + $rootScope.globalInfo.user.ids }).then(function (data) {
		$scope.items = data.data.data;
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})
	$scope.lockerClick = function (id) {
		$rootScope.lockerClickId = id;
		console.log(id)
		location.href = '#/tab/my/lockerDetails/' + id;
	}
})
/**
 * 更衣柜 柜子详情
 */
app.controller("lockerDetailsCtrl", function ($scope, $http, dialogsManager, $ionicHistory, $rootScope) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$http({ method: 'get', url: 'http://qa.aixingfu.net/v1/api-member/get-member-cabinet-info?memberId=' + $rootScope.globalInfo.user.ids + "&memberCabinetId=" + $rootScope.lockerClickId }).then(function (data) {
		$scope.items = data.data.data;
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})
})

/**
 * 我的二维码页面
 */
app.controller('myTowCodeCtrl', function ($scope, $http, $rootScope, dialogsManager, $ionicHistory) {
	//返回上一页
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	//请求会员信息
	var url = 'http://qa.aixingfu.net/v1/api-member/get-member-detail?memberId=' + $rootScope.globalInfo.user.ids;
	$http({
		method: 'get',
		url: url,
	}).then(function (data) {
		$scope.ids = data.data.id;
		$scope.username = data.data.username;
		$scope.pic = data.data.pic;
	}, function (error) {
		console.log(error);
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})
	//请求二维码
	var url1 = 'http://qa.aixingfu.net/v1/api-qr-code/qr-code?memberId=' + $rootScope.globalInfo.user.ids;
	$http({
		method: 'get',
		url: url1,
	}).then(function (data) {
		$scope.item = data.data.img;
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})

});

/**
 * 个人信息页面
 */
app.controller('myMessageCtrl', function ($rootScope, $scope, $http, dialogsManager, $ionicHistory) {
	//返回上一页
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	var url = 'http://qa.aixingfu.net/v1/api-member/get-member-detail?memberId=' + $rootScope.globalInfo.user.ids;
	$http({
		method: 'get',
		url: url,
	}).then(function (data) {
		$scope.ids = data.data.id;
		$scope.username = data.data.username;
		$scope.pic = data.data.pic;
		$scope.sex = data.data.sex;
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})

	$scope.tabModifyNickname = function () {
		location.href = '#/tab/my/myMessage/modifyNickname'
	}
});
// 修改个人信息
app.controller('modifyNicknameCtrl', function ($scope, $rootScope, $state, $ionicHistory, $http, Storage, dialogsManager) {
	//返回上一页
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	var url1 = 'http://qa.aixingfu.net/v1/api-member/get-member-detail?memberId=' + $rootScope.globalInfo.user.ids;
	$http({
		method: 'get',
		url: url1,
	}).then(function (data) {
		$rootScope.input = {
			usernamewww: data.data.username,
			id: Storage.get('user').ids
		}

	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})

	$scope.buttons = function () {

		var document = { name: $rootScope.input.usernamewww, memberId: $rootScope.globalInfo.user.ids }
		var url = 'http://qa.aixingfu.net/v1/api-member/update-member-detail';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
			if (success.data.message == '修改成功') {
				$scope.showMessage = function () {
					dialogsManager.showMessage("修改成功");
				}
				$scope.showMessage();
				$ionicHistory.goBack(-1);
			}
			if (success.data.status == 'error') {

				for (var key in success.data.data.data) {
					if (success.data.data.data.hasOwnProperty(key)) {
						var element = success.data.data.data[key];
						$scope.showMessage = function () {
							dialogsManager.showMessage(element);
						}
						$scope.showMessage();
					}
				}
			}
		}, function (error) {
			console.log(error);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}
})
/**
 * 个人信息页面
 */
app.controller('mySetCtrl', function ($scope, $http, Storage, dialogsManager, $ionicHistory, $state, $rootScope) {
	//返回上一页
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$scope.logout = function () {
		// localStorage.clear();
		Storage.remove('user');
		$rootScope.globalInfo.user = { ids: '' };
		$state.go('tab.passwordEnter')
	}

	$scope.changePassword = function () {
		location.href = '#/tab/my/changePassword';
	}
});

/**
 * Created by DELL on 2017/4/21.
 * 验证码 登录页面
 */
app.controller('loginCtrl', function ($scope, $rootScope, Storage, $http, $interval, $state, dialogsManager, $timeout, $ionicLoading) {
	//点击跳转课程页面首页
	$rootScope.backCourse = function () {
		$state.go('tab.course')
	}
	//初始化，避免ng-model绑定取不到值
	$scope.input = {
		loginPhoneNumber: '',
		loginVerificationCode: ''
	}

	/**
	 * 获取验证码
	 */
	var wait = 60;

	function getVerificationCode(o) {

		if ($scope.input.loginPhoneNumber == '') {
			return
		}
		else if ($scope.input.loginPhoneNumber != '') {
			if (wait == 0) {
				o.removeAttribute("disabled");
				o.value = "免费获取验证码";
				wait = 60;
			} else {
				o.setAttribute("disabled", true);
				o.value = "重新发送(" + wait + ")";
				wait--;
				setTimeout(function () {
					getVerificationCode(o)
				},
					1000)
			}
		}
	}
	document.getElementById("getCode").onclick = function () {
		getVerificationCode(this);
		var document = { mobile: $scope.input.loginPhoneNumber }
		var url = 'http://qa.aixingfu.net/v1/api-member/create-code';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {

		}, function (error) {
			console.log(error);
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}

	/**
	 * 登录
	 */
	$scope.Signin = function () {
		$ionicLoading.show({
			noBackdrop: true,
			template: '<p class="item-myicon"><ion-spinner icon="bubbles" class="spinner-balanced"></ion-spinner></p>'
		});
		if ($scope.input.loginPhoneNumber == '' || $scope.input.loginPhoneNumber == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('请输入手机号');
			}
			$scope.showMessage();
		}
		if ($scope.input.loginVerificationCode == '' || $scope.input.loginVerificationCode == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('请输入验证码');
			}
			$scope.showMessage();
		}
		var document = { mobile: $scope.input.loginPhoneNumber, code: $scope.input.loginVerificationCode }

		var url = 'http://qa.aixingfu.net/v1/api-member/login-code';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
			if (success.data.message == '登录成功') {

				for (var key in success.data.data) {
					if (success.data.data.hasOwnProperty(key)) {
						$scope.mobiles = success.data.data.mobile;
						$scope.ids = success.data.data.id;
						$scope.identify = success.data.data.identify;
						$scope.identify = success.data.data.identify;
						$scope.venueId = success.data.data.venue_id;
					}
				}
				var users = {
					mobile: $scope.mobiles,
					ids: $scope.ids,
					identify: $scope.identify,
					venueId: $scope.venueId
				}
				Storage.set("user", users);
				$rootScope.globalInfo.user = users;
				// location.href = '#/tab/league';
				$timeout(function () {
					$ionicLoading.hide();
				}, 1000);

				$state.go('tab.league', {}, { reload: true })
			} else if (success.data.status == 'error') {

				$ionicLoading.hide();
				for (var keyWord in success.data.data) {
					if (keyWord == 'mobile') {
						//手机号信息提示
						for (var key in success.data.data.mobile) {
							if (success.data.data.mobile.hasOwnProperty(key)) {
								var element = success.data.data.mobile[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(element);
								}
								$scope.showMessage();
								return;
							}
						}
					} else if (keyWord == 'code') {
						//验证码信息提示
						for (var key in success.data.data.code) {
							if (success.data.data.code.hasOwnProperty(key)) {
								var element = success.data.data.code[key];

								$scope.showMessage = function () {
									dialogsManager.showMessage(element);
								}
								$scope.showMessage();
							}
						}
					}
				}
			}
			else if (success.data.message == '您还未注册！') {
				$ionicLoading.hide();
				$scope.showMessage = function () {
					dialogsManager.showMessage(success.data.message);
				}
				$scope.showMessage();
			}
		}, function (error) {
			$ionicLoading.hide();

			console.log(error);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}

	/**
	 * 
	 */
	$scope.passwordEnter = function () {
		location.href = '#/tab/my/passwordEnter';
	}
	$scope.register = function () {
		location.href = '#/tab/my/register';
	}
	$scope.forgetPassword = function () {
		location.href = '#/tab/my/forgetPassword';
	}
});

/**
 * Created by DELL on 2017/4/21.
 * 使用账号密码登录页面
 */
app.controller('passwordEnterCtrl', function ($scope, $timeout, $rootScope, $http, $state, $ionicLoading, $ionicHistory, Storage, dialogsManager) {
	if ($rootScope.globalInfo.user.ids) {
		$state.go('tab.league', {}, { reload: true })
	}

	//点击跳转课程页面首页
	$rootScope.backCourse = function () {
		$state.go('tab.course')
	}

	/**
	 * 登录
	 */
	$scope.input = {
		miPhoneNumber: '',
		mipassword: ''
	}

	$scope.Signin = function () {

		$ionicLoading.show({
			content: 'Loading',
			animation: 'fade-in',
			showBackdrop: true,
			maxWidth: 200,
			showDelay: 0
		});

		if ($scope.input.miPhoneNumber == '' || $scope.input.miPhoneNumber == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入账号");
			}
			$scope.showMessage();
			return
		}
		if ($scope.input.mipassword == '' || $scope.input.mipassword == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入密码");
			}
			$scope.showMessage();
			return
		}
		var document = { mobile: $scope.input.miPhoneNumber, password: $scope.input.mipassword }

		var url = 'http://qa.aixingfu.net/v1/api-member/login';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
			console.log(success)
			if (success.data.message == '登录成功') {

				$timeout(function () {
					$ionicLoading.hide();
				}, 1000);

				for (var key in success.data.data) {
					if (success.data.data.hasOwnProperty(key)) {
						$scope.mobiles = success.data.data.mobile;
						$scope.passwords = success.data.data.password;
						$rootScope.idslogin = success.data.data.id;
						$scope.venueId = success.data.data.venue_id;
					}
				}
				var users = {
					mobile: $scope.mobiles,
					password: $scope.passwords,
					ids: $rootScope.idslogin,
					identify: success.data.data.identify,
					venueId: $scope.venueId
				}

				Storage.set("user", users);
				$rootScope.globalInfo.user = users;

				$state.go('tab.league', {}, { reload: true })
			}
			if (success.data.status == 'error') {
				$ionicLoading.hide();
				for (var key in success.data.data) {
					if (key == 'mobile') {
						//手机号信息提示
						for (var key in success.data.data.mobile) {
							if (success.data.data.mobile.hasOwnProperty(key)) {
								var element = success.data.data.mobile[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(element);
								}
								$scope.showMessage();
							}
						}
					} else if (key == 'password') {
						//密码信息提示
						for (var key in success.data.data.password) {
							if (success.data.data.password.hasOwnProperty(key)) {
								var element = success.data.data.password[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(element);
								}
								$scope.showMessage();
							}
						}
					}
				}
			}
			if (success.data.message == "您还未注册！") {
				$ionicLoading.hide();
				for (var key in success.data.data) {
					if (key == 'mobile') {
						//手机号信息提示
						for (var key in success.data.data.mobile) {
							if (success.data.data.mobile.hasOwnProperty(key)) {
								var element = success.data.data.mobile[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(element);
								}
								$scope.showMessage();
							}
						}
					}
				}
			}

		}, function (error) {
			console.log(error);
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
			return;
		})
	}
	$scope.login = function () {
		location.href = '#/tab/my/login';
	}
	$scope.register = function () {
		location.href = '#/tab/my/register';
	}
	$scope.forgetPassword = function () {
		location.href = '#/tab/my/forgetPassword';
	}
});

/**
 * 选择公司
 */
app.controller("selectCompanyCtrl", function ($scope, $timeout, $rootScope, $http, dialogsManager, $ionicLoading, $ionicHistory) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$scope.init = function () {
		$http({ method: "get", url: 'http://qa.aixingfu.net/v1/api-venue/get-all-company' }).then(function (data) {
			$scope.items = data.data.data;
		}, function (error) {
			console.log(error)
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}
	$scope.init()
	$scope.selectVenues = function (id) {
		$rootScope.selectVenuesId = id;
		location.href = '#/tab/my/chooseVenues/' + id;
	}
})
app.controller("chooseVenuesCtrl", function ($scope, $timeout, $rootScope, $http, dialogsManager, $state, $ionicLoading, $ionicHistory) {
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$http({ method: "get", url: 'http://qa.aixingfu.net/v1/api-venue/get-all-venue?companyId=' + $rootScope.selectVenuesId }).then(function (data) {
		$scope.items = data.data.data;
	}, function (error) {
		console.log(error)
		$scope.showMessage = function () {
			dialogsManager.showMessage('系统错误,请联系工作人员');
		}
		$scope.showMessage();
	})
	$scope.chooseVenues = function (id, name) {
		$rootScope.chooseVenuesId = id;
		$rootScope.chooseVenuesName = name;
		$state.go("tab.register")
	}
})

/**
 * Created by DELL on 2017/4/21.
 * 注册页面
 */
app.controller('registerCtrl', function ($scope, $timeout, $rootScope, $http, dialogsManager, $ionicLoading) {
	//点击跳转课程页面首页
	$rootScope.backCourse = function () {
		$state.go('tab.course')
	}

	$scope.inputs = {
		PhoneNumbersWwww: '',
		registerVerificationCode: '',
		registerPassword: '',
	}

	$scope.chooseVenues = function () {
		location.href = '#/tab/my/selectCompany';
	}
	//点击查看密码
	var flag = true;
	$scope.checkPassword = function () {
		if (flag) {
			$('#password').attr({ 'type': 'text' })
			flag = false;
		} else {
			$('#password').attr({ 'type': 'password' })
			flag = true;
		}
	}
	/**
	 * 获取验证码
	 */
	var wait = 60;

	function getVerificationCode(o) {
		if ($scope.inputs.PhoneNumbersWwww == '') {
			return
		}
		else if ($scope.inputs.PhoneNumbersWwww != '') {
			if (wait == 0) {
				o.removeAttribute("disabled");
				o.value = "免费获取验证码";
				wait = 60;
			} else {
				o.setAttribute("disabled", true);
				o.value = "重新发送(" + wait + ")";
				wait--;
				setTimeout(function () {
					getVerificationCode(o)
				}, 1000)
			}
		}

	}
	document.getElementById("registerGetCode").onclick = function () {
		getVerificationCode(this);

		var document = { mobile: $scope.inputs.PhoneNumbersWwww }

		var url = 'http://qa.aixingfu.net/v1/api-member/create-code';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
		}, function (error) {
			console.log(error);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}

	$scope.register = function () {
		$ionicLoading.show({
			noBackdrop: true,
			template: '<p class="item-myicon"><ion-spinner icon="circles" class="spinner-balanced"></ion-spinner></p>'
		});

		if ($rootScope.chooseVenuesId == '' || $rootScope.chooseVenuesId == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('请选择场馆');
			}
			$scope.showMessage();
			return
		}
		if ($scope.inputs.PhoneNumbersWwww == '' || $scope.inputs.PhoneNumbersWwww == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('请输入手机号');
			}
			$scope.showMessage();
			return
		}
		if ($scope.inputs.registerVerificationCode == '' || $scope.inputs.registerVerificationCode == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('请输入验证码');
			}
			$scope.showMessage();
			return
		}
		if ($scope.inputs.registerPassword == '' || $scope.inputs.registerPassword == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('请输入密码');
			}
			$scope.showMessage();
			return
		}
		var document = { mobile: $scope.inputs.PhoneNumbersWwww, password: $scope.inputs.registerPassword, code: $scope.inputs.registerVerificationCode,companyId:$rootScope.selectVenuesId, venueId: $rootScope.chooseVenuesId }
		var url = 'http://qa.aixingfu.net/v1/api-member/sign-up';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
			if (success.data.message == '注册成功') {
				$timeout(function () {
					$ionicLoading.hide();
				}, 1000);
				location.href = '#/tab/my/passwordEnter';
			}
			else if (success.data.message == "手机号已注册！") {
				$ionicLoading.hide();
				$scope.showMessage = function () {
					dialogsManager.showMessage(success.data.message);
				}
				$scope.showMessage();
			}
			else if (success.data.status == 'error') {
				$ionicLoading.hide();
				for (var key in success.data.data) {
					var element = success.data.data;
					if (key == 'mobile') {
						//手机信息提示
						for (var b in element.mobile) {
							if (element.mobile.hasOwnProperty(b)) {
								var qb = element.mobile[b];
								$scope.showMessage = function () {
									dialogsManager.showMessage(qb);
								}
								$scope.showMessage();
								return;
							}
						}
					}

					//验证码信息提示
					if (key == 'code') {
						for (var a in element.code) {
							if (element.code.hasOwnProperty(a)) {
								var qa = element.code[a];
								$scope.showMessage = function () {
									dialogsManager.showMessage(qa);
								}
								$scope.showMessage();
								return;
							}
						}
					} else if (key == 'password') {
						for (var c in element.password) {
							if (element.password.hasOwnProperty(c)) {
								var qc = element.password[c];
								$scope.showMessage = function () {
									dialogsManager.showMessage(qc);
								}
								$scope.showMessage();
							}
						}
					}
				}
			}

		}, function (error) {
			console.log(error);
			$ionicLoading.hide();

			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}
	$scope.login = function () {
		location.href = '#/tab/my/login';
	}

});
/**
 * Created by DELL on 2017/4/21.
 * 我的模块 修改密码页面
 */
app.controller('changePasswordCtrl', function ($scope, $rootScope, $http, dialogsManager, $ionicHistory, $ionicLoading, $timeout) {
	//返回上一页
	$scope.backPrePage = function () {
		$ionicHistory.goBack();
	}
	$scope.input = {
		changePhoneNumber: '',
		changeVerificationCode: '',
		changeOldPassword: '',
		changeNewPassword: ''
	}
	/**
	 * 获取验证码
	 */
	var wait = 60;

	function getVerificationCode(o) {
		if ($scope.input.changePhoneNumber == '') {
			return
		}
		else if ($scope.input.changePhoneNumber != '') {
			if (wait == 0) {
				o.removeAttribute("disabled");
				o.value = "免费获取验证码";
				wait = 60;
			} else {
				o.setAttribute("disabled", true);
				o.value = "重新发送(" + wait + ")";
				wait--;
				setTimeout(function () {
					getVerificationCode(o)
				},
					1000)
			}
		}
	}

	document.getElementById("changePasswordGetCode").onclick = function () {
		getVerificationCode(this);
		var document = { mobile: $scope.input.changePhoneNumber }

		var url = 'http://qa.aixingfu.net/v1/api-member/create-code';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
		}, function (error) {
			console.log(error);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}

	$scope.click = function () {

		$ionicLoading.show({
			noBackdrop: true,
			template: '<p class="item-myicon"><ion-spinner icon="circles" class="spinner-balanced"></ion-spinner></p>'
		});

		if ($scope.input.changePhoneNumber == '' || $scope.input.changePhoneNumber == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入手机号");
			}
			$scope.showMessage();
			return
		}
		if ($scope.input.changeVerificationCode == '' || $scope.input.changeVerificationCode == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入验证码");
			}
			$scope.showMessage();
			return
		}
		if ($scope.input.changeOldPassword == '' || $scope.input.changeOldPassword == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入旧密码");
			}
			$scope.showMessage();
			return
		}
		if ($scope.input.changeNewPassword == '' || $scope.input.changeNewPassword == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入新密码");
			}
			$scope.showMessage();
			return
		}
		var document = { mobile: $scope.input.changePhoneNumber, oldPassword: $scope.input.changeOldPassword, password: $scope.input.changeNewPassword, code: $scope.input.changeVerificationCode }
		var url = 'http://qa.aixingfu.net/v1/api-member/reset-password';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
			if (success.data.message == '修改成功') {
				$timeout(function () {
					$ionicLoading.hide();
				}, 1000);
				location.href = '#/tab/my/passwordEnter';
			}
			if (success.data.status == 'error') {
				$ionicLoading.hide();
				for (var key in success.data.data) {
					if (success.data.data.hasOwnProperty(key)) {
						var element = success.data.data;
						// 旧密码信息提示
						if (key == 'oldPassword') {
							for (var d in element.oldPassword) {
								if (element.oldPassword.hasOwnProperty(d)) {
									var qOld = element.oldPassword[d];
									$scope.showMessage = function () {
										dialogsManager.showMessage(qOld);
									}
									$scope.showMessage();
									return;
								}
							}
						}
						// 密码信息提示
						if (key == 'password') {
							for (var c in element.password) {
								if (element.password.hasOwnProperty(c)) {
									var qc = element.password[c];
									$scope.showMessage = function () {
										dialogsManager.showMessage(qc);
									}
									$scope.showMessage();
									return;
								}
							}
						}
						//验证码信息提示
						if (key == 'code') {
							for (var a in element.code) {
								if (element.code.hasOwnProperty(a)) {
									var qa = element.code[a];
									$scope.showMessage = function () {
										dialogsManager.showMessage(qa);
									}
									$scope.showMessage();
									return;
								}
							}
						}
						//手机信息提示
						if (key == 'mobile') {
							for (var b in element.mobile) {
								if (element.mobile.hasOwnProperty(b)) {
									var qb = element.mobile[b];
									$scope.showMessage = function () {
										dialogsManager.showMessage(qb);
									}
									$scope.showMessage();
									return;
								}
							}
						}


					}
				}
			}
		}, function (error) {
			console.log(error);
			$ionicLoading.hide();

			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}
});
//找回密码
app.controller('forgetPasswordCtrl', function ($scope, $rootScope, $http, dialogsManager, $ionicLoading, $timeout) {
	$scope.inputForget = {
		forgetPhoneNumber: '',
		forgetVerificationCode: '',
		forgetPassword: ''
	}
	//点击查看密码
	var flag = true;
	$scope.checkPassword = function () {
		if (flag) {
			$('#forgetPassword').attr({ 'type': 'text' })
			flag = false;
		} else {
			$('#forgetPassword').attr({ 'type': 'password' })
			flag = true;
		}
	}
	/**
	 * 获取验证码
	 */
	var wait = 60;

	function getVerificationCode(o) {
		if ($scope.inputForget.forgetPhoneNumber == '') {
			return
		}
		else if ($scope.inputForget.forgetPhoneNumber != '') {
			if (wait == 0) {
				o.removeAttribute("disabled");
				o.value = "免费获取验证码";
				wait = 60;
			} else {
				o.setAttribute("disabled", true);
				o.value = "重新发送(" + wait + ")";
				wait--;
				setTimeout(function () {
					getVerificationCode(o)
				},
					1000)
			}
		}
	}
	document.getElementById("forgetGetCode").onclick = function () {
		getVerificationCode(this);

		var document = { mobile: $scope.inputForget.forgetPhoneNumber }
		var url = 'http://qa.aixingfu.net/v1/api-member/create-code';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
		}, function (error) {
			console.log(error);
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}

	$scope.logins = function () {
		console.log($scope.inputForget)
		$ionicLoading.show({
			noBackdrop: true,
			template: '<p class="item-myicon"><ion-spinner icon="bubbles" class="spinner-balanced"></ion-spinner></p>'
		});
		if ($scope.inputForget.forgetPhoneNumber == '' || $scope.inputForget.forgetPhoneNumber == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入手机号");
			}
			$scope.showMessage();
			return
		}
		if ($scope.inputForget.forgetVerificationCode == '' || $scope.inputForget.forgetVerificationCode == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入验证码");
			}
			$scope.showMessage();
			return
		}
		if ($scope.inputForget.forgetPassword == '' || $scope.inputForget.forgetPassword == undefined) {
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage("请输入密码");
			}
			$scope.showMessage();
			return
		}
		var document = { mobile: $scope.inputForget.forgetPhoneNumber, password: $scope.inputForget.forgetPassword, code: $scope.inputForget.forgetVerificationCode }
		var url = 'http://qa.aixingfu.net/v1/api-member/retrieve-password';
		$http({
			method: 'post',
			url: url,
			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
			data: $.param(document)
		}).then(function (success) {
			if (success.data.message == '修改成功') {
				// 密码 登录
				$ionicLoading.hide();
				location.href = '#/tab/my/passwordEnter';
			}
			if (success.data.status == 'error') {
				// 密码 登录
				$ionicLoading.hide();
				//登录失败时的信息提示
				for (var keyWord in success.data.data) {

					var element = success.data.data;
					if (keyWord == 'mobile') {
						for (var key in element.mobile) {
							if (element.mobile.hasOwnProperty(key)) {
								var message = element.mobile[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(message);
								}
								$scope.showMessage();
								return;
							}
						}
					} else if (keyWord == 'code') {
						for (var key in element.code) {
							if (element.code.hasOwnProperty(key)) {
								var message = element.code[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(message);
								}
								$scope.showMessage();
							}
						}
					} else if (keyWord == 'password') {
						for (var key in element.password) {
							if (element.password.hasOwnProperty(key)) {
								var message = element.password[key];
								$scope.showMessage = function () {
									dialogsManager.showMessage(message);
								}
								$scope.showMessage();
							}
						}
					}
				}
			}
		}, function (error) {
			console.log(error);
			$ionicLoading.hide();
			$scope.showMessage = function () {
				dialogsManager.showMessage('系统错误,请联系工作人员');
			}
			$scope.showMessage();
		})
	}
	$scope.login = function () {
		location.href = '#/tab/my/login';
	}
});

app.controller("completesECtrl", function ($scope, $state) {
	$scope.backHomepage = function () {
		$state.go("tab.my")
	}
})

app.controller('mapMyCtrl', function ($rootScope, $scope, $stateParams, $http, $ionicHistory) {
	//返回上一页
	$scope.backPrivate = function () {
		$ionicHistory.goBack();
	}

	//创建和初始化地图函数：
	function initMap() {
		createMap();//创建地图
		setMapEvent();//设置地图事件
		addMapControl();//向地图添加控件
		addMarker();//向地图中添加marker
	}


	//创建地图函数：
	function createMap() {
		var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
		var point = new BMap.Point(113.676957, 34.763269);//定义一个中心点坐标
		map.centerAndZoom(point, 17);//设定地图的中心点和坐标并将地图显示在地图容器中
		window.map = map;//将map变量存储在全局
	}



	//地图事件设置函数：
	function setMapEvent() {
		map.disableDragging();//禁用地图拖拽事件
		map.disableScrollWheelZoom();//禁用地图滚轮放大缩小，默认禁用(可不写)
		map.disableDoubleClickZoom();//禁用鼠标双击放大
		map.disableKeyboard();//禁用键盘上下左右键移动地图，默认禁用(可不写)
	}

	//地图控件添加函数：
	function addMapControl() {
	}


	//标注点数组
	var markerArr = [{ title: "", content: "我爱运动健身馆大上海城店", point: "113.676957|34.763269", isOpen: 0, icon: { w: 25, h: 25, l: -2, t: 21, x: 6, lb: 5 } }
	];
	//创建marker
	function addMarker() {
		for (var i = 0; i < markerArr.length; i++) {
			var json = markerArr[i];
			var p0 = json.point.split("|")[0];
			var p1 = json.point.split("|")[1];
			var point = new BMap.Point(p0, p1);
			var iconImg = createIcon(json.icon);
			var marker = new BMap.Marker(point, { icon: myIcon });
			var iw = createInfoWindow(i);
			var label = new BMap.Label(json.title, { "offset": new BMap.Size(json.icon.lb - json.icon.x + 10, -20) });
			marker.setLabel(label);
			map.addOverlay(marker);
			label.setStyle({
				borderColor: "#808080",
				color: "#333",
				cursor: "pointer"
			});

			(function () {
				var index = i;
				var _iw = createInfoWindow(i);
				var _marker = marker;
				_marker.addEventListener("click", function () {
					this.openInfoWindow(_iw);
				});
				_iw.addEventListener("open", function () {
					_marker.getLabel().hide();
				})
				_iw.addEventListener("close", function () {
					_marker.getLabel().show();
				})
				label.addEventListener("click", function () {
					_marker.openInfoWindow(_iw);
				})
				if (!!json.isOpen) {
					label.hide();
					_marker.openInfoWindow(_iw);
				}
			})()
		}
	}
	//创建marker
	function addMarker() {
		for (var i = 0; i < markerArr.length; i++) {
			var json = markerArr[i];
			var p0 = json.point.split("|")[0];
			var p1 = json.point.split("|")[1];
			var point = new BMap.Point(p0, p1);
			var iconImg = createIcon(json.icon);
			var marker = new BMap.Marker(point, { icon: iconImg });
			var iw = createInfoWindow(i);
			var label = new BMap.Label(json.title, { "offset": new BMap.Size(json.icon.lb - json.icon.x + 10, -20) });
			marker.setLabel(label);
			map.addOverlay(marker);
			label.setStyle({
				borderColor: "#808080",
				color: "#333",
				cursor: "pointer"
			});

			(function () {
				var index = i;
				var _iw = createInfoWindow(i);
				var _marker = marker;
				_marker.addEventListener("click", function () {
					this.openInfoWindow(_iw);
				});
				_iw.addEventListener("open", function () {
					_marker.getLabel().hide();
				})
				_iw.addEventListener("close", function () {
					_marker.getLabel().show();
				})
				label.addEventListener("click", function () {
					_marker.openInfoWindow(_iw);
				})
				if (!!json.isOpen) {
					label.hide();
					_marker.openInfoWindow(_iw);
				}
			})()
		}
	}
	//创建InfoWindow
	function createInfoWindow(i) {
		var json = markerArr[i];
		var iw = new BMap.InfoWindow("<b class='iw_poi_title' title='" + json.title + "'>" + json.title + "</b><div class='iw_poi_content'>" + json.content + "</div>");
		return iw;
	}
	//创建一个Icon
	function createIcon(json) {
		var icon = new BMap.Icon("http://map.baidu.com/image/us_mk_icon.png", new BMap.Size(json.w, json.h), { imageOffset: new BMap.Size(-json.l, -json.t), infoWindowOffset: new BMap.Size(json.lb + 5, 1), offset: new BMap.Size(json.x, json.h) })
		return icon;
	}

	initMap();//创建和初始化地图
})